package com.fysports.web.model.app;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Page;
import com.fysports.web.model.BaseModel;


/**
 * App推送
 * Created by konbluesky
 * Date : 15/7/5 下午10:47
 * Project :jdmdata_server
 */
public class AppPush extends BaseModel<AppPush> {
    private static Log log = Log.getLog(AppPush.class);
    public final static AppPush dao = new AppPush();
    public static final String COL_PLATFORM = "platform";
    public static final String COL_MSGTEXT = "msgtext";
    public static final String COL_MSGTITLE = "msgtitle";
    public static final String COL_RESULT = "result";


    public AppPush() {
        if (this.getStr(COL_UUID) == null || this.getStr(COL_UUID).length() == 0) {
            this.set(COL_UUID, generateUUID());
        }
    }

    public Page<AppPush> paginateSysMessage(int pageNum, int pageSize,String msgtype, String useruuid) {
        String sql = "select tmp.* ";
        String sqlExceptSelect = "from ((select ap1.*,'0' as isreadflag from app_push ap1 where ap1.uuid not in (select aus.msguuid from app_user_sysmsg aus where aus.useruuid = ?) and ap1.liveflag = ?) union (select ap2.*,max(aus.isreadflag) from app_push ap2 left join app_user_sysmsg aus on ap2.uuid = aus.msguuid where ap2.msgtype = ? and aus.useruuid = ? and ap2.liveflag = ? group by ap2.uuid) order by createtime desc) as tmp";
        Page<AppPush> list= AppPush.dao.paginate(pageNum, pageSize, sql, sqlExceptSelect, useruuid, "1", msgtype, useruuid, "1");
        return list;
    }
}